package controllers;

import com.fasterxml.jackson.databind.JsonNode;
import models.Customer;
import play.mvc.BodyParser;
import play.mvc.Controller;
import play.mvc.*;

import play.libs.Json;

import static play.libs.Json.toJson;

/**
 * Created by duzi on 7/7/15.
 */
@BodyParser.Of(BodyParser.Json.class)
public class vip  extends Controller{

    public Result addCustomer(){
        JsonNode customerJson = request().body().asJson();
        String name = customerJson.get("name").asText();
        String pass = customerJson.get("passwd").asText();
        String addr = customerJson.get("address").asText();
        String phone = customerJson.get("phone").asText();

        Customer c = new Customer();
        c.name = name;
        c.address = addr;
        c.phone = phone;
        c.isvip = "1";
        c.passwd = pass;
        c.save();

        return ok(toJson(c));
    }
}
